import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { Menu } from '../../menu/entities/menu.entity';
import { CommonEntity } from '../../../../util/entity/common.entity';

@Entity('sys_role')
export class Role extends CommonEntity {
  // name和code都唯一
  @Column({ length: '50', comment: '角色名称' })
  name: string;

  // 手动校验唯一性,因为里面有deleteDate,不是真删除
  @Column({ length: '50', comment: '角色编码' })
  code: string;

  @Column({ default: 1, comment: '排序' })
  sort: number;

  @ManyToMany(() => User, (user) => user.roles)
  users: User[];

  @ManyToMany(() => Menu, (menu) => menu.roles)
  @JoinTable({ name: 'sys_role_menu' })
  menus: Menu[];
}
